package com.leo;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;

/**
 * @ClassName PlatformTools
 * @Description 工具类介绍
 * @Author wangss
 * @date 2020.05.16 00:22
 * @Version 1.0
 */
public class PlatformTools extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        System.out.println("start Thread = " + Thread.currentThread().getName());

        // 这个方法相当于在主线程中进行刷新，可以操作简单的刷新、倒计时等，类似于多任务场景，但是处理太多页面会死机
        // 更新组件、更新按钮，别做大量操作
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                System.out.println("run Thread = " + Thread.currentThread().getName());
                int i = 0;
                while (i <= 10) {
                    try {
                        Thread.sleep(1000);
                        System.out.println(i);
                        if (i == 10) {
                            Platform.exit();
                        }
                        i++;

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        System.out.println("runlater 后边");
    }
}
